﻿<UserControl x:Class="Marc.JwOrgClient.Views.PodcastDownloadView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:vm="clr-namespace:Marc.JwOrgClient.ViewModels" xmlns:v="clr-namespace:Marc.JwOrgClient.Views" xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
    mc:Ignorable="d" d:DesignHeight="400" d:DesignWidth="600">

  <UserControl.Resources>
    <v:DownloadStateToForegroundConverter x:Key="DownloadStateToForegroundConverter" />
    <Style x:Key="LabelStyle" TargetType="TextBlock">
      <Setter Property="Margin" Value="5" />
      <Setter Property="HorizontalAlignment" Value="Right" />
      <Setter Property="FontWeight" Value="Bold" />
      <Setter Property="VerticalAlignment" Value="Top" />
    </Style>
  </UserControl.Resources>

  <xctk:BusyIndicator d:DataContext="{d:DesignInstance vm:PodcastDownloadViewModel}" DataContext="{Binding Source={StaticResource Locator}, Path=PodcastDownloadViewModel}"
                      IsBusy="{Binding IsDownloading}">
    
    <xctk:BusyIndicator.BusyContentTemplate>
      <DataTemplate>
        <Grid Margin="5" Width="350">
          <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
          </Grid.RowDefinitions>
          <TextBlock Grid.Row="0" HorizontalAlignment="Center" Margin="3" FontWeight="Bold" Text="Download läuft"/>
          <TextBlock Grid.Row="1" HorizontalAlignment="Center" Margin="3" Text="{Binding Source={StaticResource Locator}, Path=PodcastDownloadViewModel.CurrentDownload}"/>
          <ProgressBar Grid.Row="2" HorizontalAlignment="Center" Margin="10" Height="15" Width="250" Value="{Binding Source={StaticResource Locator}, Path=PodcastDownloadViewModel.DownloadProgress}" Maximum="100" IsIndeterminate="False" />
          <Button Grid.Row="3" HorizontalAlignment="Center" Margin="5"  Content="Abbrechen" Command="{Binding Source={StaticResource Locator}, Path=PodcastDownloadViewModel.CancelDownloadCommand}" />
        </Grid>
      </DataTemplate>
    </xctk:BusyIndicator.BusyContentTemplate>
    <xctk:BusyIndicator.ProgressBarStyle>
      <Style TargetType="ProgressBar">
        <Setter Property="Visibility" Value="Collapsed"/>
      </Style>
    </xctk:BusyIndicator.ProgressBarStyle>
    <Grid>
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>

      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />

      </Grid.ColumnDefinitions>

      <TextBlock Grid.Row="0" Grid.Column="0" Style="{StaticResource LabelStyle}" Text="Sprache" />
      <ComboBox Grid.Row="0" Grid.Column="1" Margin="3" ItemsSource="{Binding Languages}" SelectedItem="{Binding SelectedLanguage, Mode=TwoWay}" DisplayMemberPath="Name" />

      <TextBlock Grid.Row="1" Grid.Column="0" Style="{StaticResource LabelStyle}" Text="Zielordner" />
      <Grid Grid.Row="1" Grid.Column="1">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>

        <TextBox Grid.Column="0" Margin="3" Text="{Binding RootPath}" />
        <Button Grid.Column="1" Margin="3" Content=" ... " Command="{Binding OpenBrowseDialog}" />
      </Grid>


      <TextBlock Grid.Row="2" Grid.Column="0" Style="{StaticResource LabelStyle}" Text="Benennungsschema" />
      <ComboBox Grid.Row="2" Grid.Column="1" Margin="3" ItemsSource="{Binding NamingStrategies}" SelectedItem="{Binding SelectedNamingStrategy, Mode=TwoWay}" DisplayMemberPath="Name" />

      <TextBlock Grid.Row="3" Grid.Column="0" Style="{StaticResource LabelStyle}" Text="Zeitschrift" Margin="0,0,5,5" VerticalAlignment="Bottom" />
      <ItemsControl Grid.Row="3" Grid.Column="1" Margin="3" ItemsSource="{Binding MagazineTypes}">
        <ItemsControl.ItemTemplate>
          <DataTemplate>
                        <CheckBox Content="{Binding Name}" Command="{Binding DataContext.ToggleMagazinSelectionCommand, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" CommandParameter="{Binding}" />
          </DataTemplate>
        </ItemsControl.ItemTemplate>
      </ItemsControl>

      <DataGrid Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" Margin="3" ItemsSource="{Binding Chapters}" AutoGenerateColumns="False" CanUserResizeRows="False" RowHeaderWidth="0">
        <DataGrid.Columns>
          <DataGridTemplateColumn Header="Zeitschrift">
            <DataGridTemplateColumn.CellTemplate>
              <DataTemplate DataType="vm:ChapterViewModel">
                <TextBlock Text="{Binding Chapter.Magazine.Type.Name}" Foreground="{Binding IsDownloaded, Converter={StaticResource DownloadStateToForegroundConverter}}" />
              </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
          </DataGridTemplateColumn>

          <DataGridTemplateColumn Header="Datum">
            <DataGridTemplateColumn.CellTemplate>
              <DataTemplate DataType="vm:ChapterViewModel">
                <TextBlock Text="{Binding Chapter.Magazine.DateString}" Foreground="{Binding IsDownloaded, Converter={StaticResource DownloadStateToForegroundConverter}}" />
              </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
          </DataGridTemplateColumn>

          <DataGridTemplateColumn Header="Titel" Width="*">
            <DataGridTemplateColumn.CellTemplate>
              <DataTemplate DataType="vm:ChapterViewModel">
                <StackPanel>
                  <TextBlock Text="{Binding Chapter.Title}" Foreground="{Binding IsDownloaded, Converter={StaticResource DownloadStateToForegroundConverter}}" />
                </StackPanel>
              </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
          </DataGridTemplateColumn>
        </DataGrid.Columns>
      </DataGrid>

      <Button Grid.Row="5" Grid.Column="1" Margin="3" Content="Download" HorizontalAlignment="Right" Command="{Binding DownloadCommand}" />

    </Grid>
  </xctk:BusyIndicator>
</UserControl>